<?php  
function getFeed($feed_url) {  
		$username = "canhhs91@gmail.com";
	$password = "kakacanh";
	$context = stream_context_create(array(
		'http' => array(
			'header'  => "Authorization: Basic " . base64_encode("$username:$password")
			)
		));

	//$content = file_get_contents($feed_url, false, $context);  
	
	$content = file_get_contents($feed_url);

	$x = new SimpleXmlElement($content);  

	echo "<ul>";  
	$entries = isset($x->channel->item)?$x->channel->item:$x->entry;
	foreach($entries as $entry) {  
		echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";  
	}  
	echo "</ul>";  
}


function getEmail($access_token){

	$context = stream_context_create(array(
		'http' => array(
			'method'=>'POST',
			'header'  => "GET /mail/feed/atom HTTP/1.1\r\nHost: mail.google.com\r\nContent-length: 0\r\nAuthorization: OAuth $access_token",

			)
		));


	$feed_url = "https://mail.google.com/mail/feed/atom";
	$content = file_get_contents($feed_url, false, $context); 
	
	$x = new SimpleXmlElement($content); 
	$html = "<ul>";  
	$entries = isset($x->channel->item)?$x->channel->item:$x->entry;
	foreach($entries as $entry) {  
		 $html.= "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";  
	}  
	$html .= "</ul>";
	return $html;
}